// $Id: MultiStringFieldEditor.java 82 2012-01-19 14:31:28Z huijzer@gmail.com $
package lime.application.preference;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.preference.ListEditor;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Composite;

public class MultiStringFieldEditor extends ListEditor {

	private String type;

	MultiStringFieldEditor(String name, String labelText, Composite parent, String type) {
		super(name, labelText, parent);
	}

	@Override
	protected String createList(String[] items) {
		return StringUtils.join(items, ",");
	}

	@Override
	protected String getNewInputObject() {
		String dialogTitle = "Add new " + type;
		String dialogMessage = StringUtils.capitalize(type) + ":";
		InputDialog dialog = new InputDialog(getShell(), dialogTitle, dialogMessage, "", null);
		if (dialog.open() == Window.OK) {
			return dialog.getValue();
		} else {
			return null;
		}
	}

	@Override
	protected String[] parseString(String stringList) {
		return StringUtils.split(stringList, ",");
	}
}